package com.zlx.guguanjia.mapper;

import com.zlx.guguanjia.entity.SysUser;
import com.zlx.guguanjia.mapper.provider.SysUserSqlProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;


public interface SysUserMapper extends Mapper<SysUser> {
    @SelectProvider( type= SysUserSqlProvider.class,method = "selectPage")
    List<SysUser> selectPage(Map<String,Object> map);

    //查询已分配角色的用户
    @Select("SELECT " +
            " su.id,su.name  " +
            "FROM " +
            " sys_user_role sur, " +
            " sys_user su  " +
            "WHERE " +
            " su.del_flag = 0  " +
            " AND sur.role_id = #{rid}  " +
            " AND sur.user_id = su.id")
    List<SysUser> selectByRid(long rid);

    //查询未分配角色的用户
    @Select("SELECT " +
            " id, " +
            " `name`  " +
            "FROM " +
            " sys_user sus  " +
            "WHERE " +
            "sus.del_flag=0 " +
            " AND office_id = #{oid}  " +
            " AND NOT EXISTS ( " +
            " SELECT " +
            "  1  " +
            " FROM " +
            "  sys_user_role sur  " +
            " WHERE " +
            " sur.role_id = #{rid}  " +
            " AND sus.id = sur.user_id)")
    List<SysUser> selectNotSelectRoleUser(@Param("rid") long rid,@Param("oid") long oid);
}